/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.co.pas.spaceandtime;

import java.util.Currency;
import java.util.Locale;
import javax.swing.SwingUtilities;
import za.co.pas.business.constant.Constant;
import za.co.pas.business.model.UserDataModel;
import za.co.pas.business.model.ext.CompanyDetailModel;
import za.co.pas.business.mvc.BusinessMVC;
import za.co.pas.spaceandtime.data.InitialData;
import za.co.pas.spaceandtime.threads.MVCThread;
import za.co.pas.spaceandtime.view.MainFrame;
import za.co.pas.spaceandtime.view.SplashLoginFrame;

/**
 *
 * @author alabuschagne
 */
public class Main
{

    private SplashLoginFrame splashLoginFrame;
    public static MVCThread mvcThread = new MVCThread();

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
//        Currency curr = Currency.getInstance("USD");
//        Locale trLocale = new Locale("en","US");
//        System.out.println(curr.getSymbol());
        Main main = new Main();
        main.startMe();
    }

    public Main()
    {
        Thread t = new Thread(mvcThread);
        t.start();
    }

    public void startMe()
    {

        SwingUtilities.invokeLater(new Runnable()
        {

            @Override
            public void run()
            {
                if (splashLoginFrame == null)
                {
                    splashLoginFrame = new SplashLoginFrame(getMe());
                }
                splashLoginFrame.setOk(false);
                splashLoginFrame.setVisible(true);
            }
        });
    }

    public Main getMe()
    {
        return this;
    }

    public void hideSplash()
    {
        if (splashLoginFrame != null)
        {
            if (splashLoginFrame.isOk())
            {
                SwingUtilities.invokeLater(new Runnable()
                {

                    @Override
                    public void run()
                    {
                        MainFrame mf = new MainFrame(splashLoginFrame.getLoginDetails());
                        mf.setVisible(true);
                    }
                });
            }
            else
            {
                System.exit(0);
            }
        }
        else
        {
            System.exit(0);
        }
    }

    public static void buildDB()
    {
        InitialData id = new InitialData();
        if(id.CreateAll() == null)
        {
            System.exit(0);
        }
    }
}
